package com.qf.agro.web.controller.facilities;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.common.sys.ResultInfo;
import com.qf.agro.pojo.facilities.FacilitiesConfig;
import com.qf.agro.service.facilities.FacilitiesConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/facilities/config")
public class FacilitiesConfigController {

    @Autowired
    private FacilitiesConfigService facilitiesConfigService;

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public ResultInfo findPage(@RequestParam(value = "page",defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize,
                               String name, String facilitiesId){
        //1.调用业务层查询
        Page<FacilitiesConfig> page = facilitiesConfigService.findPage(pageNum, pageSize, name,facilitiesId);
        //2.返回
        return ResultInfo.success(page);
    }

    /**
     * 新增
     * @param facilitiesConfig
     * @return
     */
    @PostMapping
    public ResultInfo save(@RequestBody FacilitiesConfig facilitiesConfig){
        facilitiesConfigService.save(facilitiesConfig);
        return ResultInfo.success("新增成功");
    }

    /**
     * 修改
     * @param facilitiesConfig
     * @return
     */
    @PutMapping
    public ResultInfo update(@RequestBody FacilitiesConfig facilitiesConfig){
        facilitiesConfigService.update(facilitiesConfig);
        return ResultInfo.success("修改成功");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping
    public ResultInfo delete(Long id){
        facilitiesConfigService.delete(id);
        return ResultInfo.success("删除成功");
    }

}
